//
//  MsgRechargeView.m
//  CedarFinancePH
//
//  Created by lshenrong on 2018/4/7.
//  Copyright © 2018年 cedarhd. All rights reserved.
//

#import "MsgRechargeView.h"
#include <UIView+TYAlertView.h>

@interface MsgRechargeView()

@property (nonatomic,copy) NSString *phone;
@property (nonatomic,weak) UITextField *inputTextField;


@end

@implementation MsgRechargeView


//316 X212
- (instancetype)initWithPhone:(NSString *)phone{
    if (self = [super init]) {
        self.backgroundColor=[UIColor whiteColor];
        self.phone = phone;
        self.layer.cornerRadius = 12.0;
        self.layer.masksToBounds = YES;
        self.frame = CGRectMake(0, 0, 316, 212);
        [self setupSubviews];
    }
    return self;
}


- (void)setupSubviews{
    UILabel *titleLbl = [[UILabel alloc]init];
    NSString *startPhone = [CedarTools replacingMiddleStarByPhone:self.phone];
    NSString *text = [NSString stringWithFormat:@"本次充值需要短信验证码,已向您的手机%@发送验证码",startPhone];
    MACRO_UILabel_Configure(titleLbl, text, kBlackColor, 17);
    titleLbl.numberOfLines = 0;
    [self addSubview:titleLbl];
    [titleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(28);
        make.right.equalTo(self).offset(-28);
        make.top.equalTo(self).offset(26);
    }];
    
    UITextField *textField =  [[UITextField alloc]init];
    textField.placeholder = @"请输入验证码";
    textField.layer.borderColor = kSeparateLineColor.CGColor;
    textField.layer.borderWidth= 0.5f;
    //[textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [self addSubview:textField];
    self.inputTextField = textField;
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(28);
        make.top.equalTo(titleLbl.mas_bottom).offset(34);
        make.size.mas_offset(CGSizeMake(176, 45));
    }];
    
    CedarButton *inputBtn =  [CedarButton buttonWithText:@"输入验证码"];
    [inputBtn PFCGStyleFontSize:15];
    [self addSubview:inputBtn];
    [inputBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(textField.mas_right).mas_offset(5);
        make.centerY.equalTo(textField);
        make.size.mas_offset(CGSizeMake(80, 45));
    }];

    UIView *hLineView =  [[UIView alloc]init];
    hLineView.backgroundColor = kSeparateLineColor;
    [self addSubview:hLineView];
    [hLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(textField.mas_bottom).mas_offset(10);
        make.height.mas_offset(0.5);
    }];
    
    CedarButton *cancelBtn =  [CedarButton buttonWithTextNoStytle:@"取消"];
    @weakify(self)
    cancelBtn.clickEvent = ^{
        @strongify(self)
        [self hideView];
    };
    [cancelBtn PFCGStyleTextColor:kGrayColor fontSize:18.0];
    [self addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).mas_offset(61);
        make.top.equalTo(hLineView).mas_offset(5);
    }];
    
    UIView *vLineView =  [[UIView alloc]init];
    vLineView.backgroundColor = kSeparateLineColor;
    [self addSubview:vLineView];
    [vLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(hLineView).mas_offset(10);
        make.bottom.equalTo(self).mas_offset(-10);
        make.width.mas_offset(0.5);
    }];
    
    CedarButton *rechargeBtn =  [CedarButton buttonWithTextNoStytle:@"充值"];
    rechargeBtn.clickEvent = ^{
        @strongify(self)
        [self hideView];
        if (self.rechargeHandelr) {
            CLog(@"recharge code:%@",self.inputTextField.text);
            self.rechargeHandelr(self.inputTextField.text);
        }
    };
    [rechargeBtn PFCGStyleTextColor:kMasterColor fontSize:18.0];
    [self addSubview:rechargeBtn];
    [rechargeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).mas_offset(-61);
        make.centerY.equalTo(cancelBtn);
    }];
}

//- (void)textFieldDidChange:(UITextField *)textField{
//    if (textField.markedTextRange == nil) {
//        CLog(@"text:%@", textField.text);
//    }
//    if (self.textChangeBlock) {
//        self.textChangeBlock(self.tag,textField.text);
//    }
//}


@end
